/*
 * @Descripttion:
 * @version:
 * @Author: mmzhang
 * @Date: 2021-07-27 16:02:34
 * @LastEditTime: 2022-01-13 10:37:01
 */
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      // {
      //   title: '公司',
      //   field: 'orgName',
      //   minWidth: 300
      // },
      {
        title: '展示名称',
        field: 'companyName',
        minWidth: 240,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.companyName,
              lineClamp: 2,
              webkitBoxOrient: 'vertical',
              display: '-webkit-box',
              whiteSpace: 'initial'
            })
          }
        }
      },
      {
        title: '关联事业部',
        field: 'orgDivisionName',
        minWidth: 120
      },
      {
        title: '关联子公司',
        field: 'orgCompanyName',
        minWidth: 120
      },
      {
        title: '关联事业处',
        field: 'orgOfficeName',
        minWidth: 120
      },
      {
        title: '已维护信息数',
        field: 'informationCount',
        minWidth: 140,
        remoteSort: true
      },
      {
        field: 'enableStatus',
        minWidth: 120,
        header: {
          filter: {
            title: '当前状态',
            key: 'enableStatus',
            placeholder: '请选择',
            select: {
              options: [
                { key: '1', value: '启用' },
                { key: '2', value: '禁用' }
              ]
            }
          }
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.enableStatus == 1 ? '启用' : '禁用'
            })
          }
        }
      },
      {
        minWidth: 160,
        header: {
          filter: dateOpt.range({
            title: '最近更新时间',
            startKey: 'startDate',
            endKey: 'endDate',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.startDate, val.endDate).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('最近更新时间跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.startDate, val.endDate).Y >= 2)
            }
          })
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.updateTime
            })
          }
        }
      },
      {
        title: '操作人',
        field: 'updateName',
        minWidth: 120,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.updateName
                ? params.row.updateWorkNo
                  ? params.row.updateName + '(' + params.row.updateWorkNo + ')'
                  : params.row.updateName
                : '-'
            })
          }
        }
      },
      {
        title: '操作',
        fixed: 'right',
        minWidth: 150,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = []
            btns.push({
              title: '查看',
              event: 'checkFun',
              data: params.row
            })

            btns.push({
              title: _this.unlocking('0212010200') ? '编辑' : '',
              event: 'editFun',
              data: params.row
            })
            btns.push({
              title: _this.unlocking('0212010300') ? (params.row.enableStatus == 1 ? '禁用' : '启用') : '',
              event: 'changeStatus',
              data: params.row
            })
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

export default Column
